<template>
  <div class="wrapper">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>会员管理</el-breadcrumb-item>
      <el-breadcrumb-item>会员积分设置</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="easy-content"
      ref="wrap">
      <el-form :model="integral"
        ref="formRule"
        :rules="rules">
        <el-form-item label="积分获取规则"
          prop="money">
          <div>
            <span>每消费</span>
            <el-input-number v-model="integral.money"
              controls-position="right"
              :min="1"
               size="small" 
              :max="100"></el-input-number>&nbsp;&nbsp;
            <span>元获取1积分</span>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <InfomationBtns v-has="'memberconfigintegral'">
      <el-button type="primary"
        size="small"
        @click="sure('formRule')">保存</el-button>
    </InfomationBtns>
  </div>
</template>

<script>
import InfomationBtns from "@/components/common/InfomationBtns";
import { getMemberIntegral, setMemberIntegral } from "@/public/js/member";
export default {
  components: {
    InfomationBtns
  },
  props: {},
  data() {
    return {
      width: "",
      rules: {
        money: [
          {
            required: true,
            message: "请输入消费金额",
            trigger: "blur"
          }
        ]
      },
      integral: {
        id: "",
        money: undefined
      }
    };
  },
  watch: {},
  computed: {},
  methods: {
    //查看会员积分
    _getMemberIntegral() {
      getMemberIntegral().then(res => {
        this.integral = res.data.integral
          ? res.data.integral
          : {
              id: "",
              money: undefined
            };
      });
    },
    // 设置会员积分
    _setMemberIntegral() {
      let {id,money} =  this.integral ;
      setMemberIntegral({id,money}).then(res=>{
        if(!res.data.errCode) {
          this.$message({
            type:'success',
            message:'保存成功'
          })
        }
      })
    },
    //保存
    sure(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this._setMemberIntegral()
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
  created() {
    this._getMemberIntegral();
  },
  mounted() {
    this.width = this.$refs["wrap"].offsetWidth + "px";
  }
};
</script>
<style lang="scss" scoped>
.wrapper {
}
</style>